package com.yiji.fintech.musfinance.common.converter;

import com.acooly.core.common.facade.OrderBase;
import com.yiji.fintech.musfinance.common.converter.base.OrderEventBaseConverter;
import com.yiji.fintech.musfinance.common.domain.base.BaseDomain;
import com.yiji.fintech.musfinance.common.exception.EmptyObjectException;
import com.yiji.fintech.musfinance.common.factory.domain.DomainFactory;
import com.yiji.fintech.musfinance.common.eventbus.event.base.BaseEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Order转换Domain
 * Created by ouwen@yiji.com} on 2017/9/13.
 */
@Service
@Slf4j
public class Order2Domain2EventConverter extends OrderEventBaseConverter {
    @Autowired
    private DomainFactory domainFactory;

    @Override
    public BaseEvent doConverter(OrderBase order){
        BaseDomain domain = domainFactory.doExcute(order);//order转换domain
        BaseEvent event = covert2Event(domain);//domain转换event
        if(event != null){
            event.setDomain(domain);
            return event;
        }
        throw new EmptyObjectException("Order转换Event异常：Order【"+order.getClass()+"】未查找到对应Event");
    }
}
